<template>
    <div class="app-container">
        <el-form :model="searchdata" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="姓名" prop="nickName">
                <el-input v-model="searchdata.nickName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="手机号" prop="phonenumber">
                <el-input v-model="searchdata.phonenumber" onkeyup="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入手机号"
                    clearable style="width: 180px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="开户行" prop="wtdAddress">
                <el-input v-model="searchdata.wtdAddress" placeholder="请输入开户行" clearable style="width: 180px;"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="办卡支行" prop="wtdAddressMessage">
                <el-input v-model="searchdata.wtdAddressMessage" placeholder="请输入办卡支行" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="添加时间">
                <el-date-picker v-model="searchdata.startTime" type="date" value-format="timestamp"
                    :picker-options="startDatePicker" placeholder="开始时间" style="width: 150px">
                </el-date-picker>
                <el-date-picker v-model="endTimes" type="date" value-format="timestamp" :picker-options="endDatePicker"
                    placeholder="结束时间" style="width: 150px">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['puser:userlist:yinhangka:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table :data="yinhangkaList">
            <el-table-column label="姓名" align="center" prop="nickName" />
            <el-table-column label="手机号" align="center" prop="phonenumber" />
            <el-table-column label="入职时间" align="center" prop="createTime">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{YY}-{MM}-{DD}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="银行卡号" align="center" prop="wtdCardId" />
            <el-table-column label="开户行" align="center" prop="wtdAddress" />
            <el-table-column label="办卡支行" align="center" prop="wtdAddressMessage" />
            <el-table-column label="添加时间" align="center" prop="wtdTime">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.wtdTime, '{YY}-{MM}-{DD} {hh}:{mm}:{ss}') || '暂无' }}</span>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="searchdata.pageNum" :limit.sync="searchdata.pageSize"
            @pagination="getList" />
    </div>
</template>
<script>
import { selectAllyinhangka, selectExcelyhks } from "@/api/puser/account.js";
export default {
    name:'yinhangka',
    data() {
        return {
            showSearch: true,
            endTimes: '',
            searchdata: {
                nickName: '',
                phonenumber: '',
                wtdAddress: '',
                wtdAddressMessage: '',
                startTime: '',
                endTime: '',
                userId: this.$route.query.userId || '',
                pageNum: 1,
                pageSize: 10,
            },
            open: false,
            yinhangkaList: [],
            loading: true,
            total: 0,
            startDatePicker: this.beginDate(),
            endDatePicker: this.processDate(),
        }
    },
    created() {
        this.getList();
    },
    methods: {
        async getList() {
            let res = await selectAllyinhangka(this.searchdata);
            if (res.code == 200) {
                this.yinhangkaList = res.rows;
                this.total = res.total;
            }
        },
        // 搜索
        handleQuery() {
            if (this.searchdata.startTime == '' && this.endTimes == "") {
                selectAllyinhangka(this.searchdata).then(response => {
                    if (response.code == 200) {
                        this.yinhangkaList = response.rows;
                        this.total = response.total;
                    }
                })
            } else if (this.searchdata.startTime == "" && this.endTimes != '') {
                this.$modal.msgError("请输入开始时间");
            } else if (this.searchdata.startTime != '' && this.endTimes == '') {
                this.$modal.msgError("请输入结束时间");
            } else if (this.searchdata.startTime != '' && this.endTimes != '' && this.searchdata.startTime > this.endTimes) {
                this.$modal.msgError("结束时间必须大于开始时间");
            } else if (this.searchdata.startTime != '' && this.endTimes != '' && this.searchdata.startTime < this.endTimes) {
                this.searchdata.endTime = this.endTimes + 24 * 60 * 60 * 1000 - 1;
                selectAllyinhangka(this.searchdata).then(response => {
                    if (response.code == 200) {
                        this.yinhangkaList = response.rows;
                        this.total = response.total;
                    }
                })
            } else if (this.queryParams.startTime == this.queryParams.endTime) {
                this.$modal.msgError("结束时间必须大于开始时间");
            }
        },
        resetQuery() {
            this.searchdata = {
                nickName: '',
                phonenumber: '',
                wtdAddress: '',
                wtdAddressMessage: '',
                startTime: '',
                endTime: '',
                userId: this.$route.query.userId || '',
            },
                this.endTimes = '';
            this.getList();
        },
        // 验证搜索框日期
        beginDate() {
            const self = this;
            return {
                disabledDate(time) {
                    //           debugger;
                    if (self.endTime) {
                        //如果结束时间不为空，则小于结束时间
                        return new Date(self.endTime).getTime() < time.getTime();
                    } else {
                        return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                },
            };
        },
        processDate() {
            const self = this;
            return {
                disabledDate(time) {
                    if (self.startTime) {
                        //如果开始时间不为空，则结束时间大于开始时间
                        return new Date(self.startTime).getTime() > time.getTime();
                    } else {
                        return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                },
            };
        },
        // 导出
      async handleExport() {
            // this.$confirm('是否确认导出所有用户数据项?', "警告", {
            //     confirmButtonText: "确定",
            //     cancelButtonText: "取消",
            //     type: "warning"
            // }).then(function () {
            //     return selectExcelyhks();
            // }).then(response => {
            //     this.$download.name(response.msg);
            // }).catch(function () { });
            const searchdata = this.searchdata;
            let res = await selectExcelyhks(searchdata);
            if (res.code == 200) {
                this.isloading = false;
                this.$download.name(res.msg);
            }
        }
    }
}
</script>